# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer:
pkgname=ocaml-camomile
_pkgname=camomile
pkgver=1.0.1
pkgrel=1
pkgdesc="A Unicode library for OCaml"
url="https://github.com/yoriyuki/Camomile"
# x86, armhf, s390x: limited by ocaml aport
arch="all !x86 !armhf !armv7 !s390x !mips !mips64"
license="LGPL-2.0-or-later"
depends="$pkgname-data=$pkgver-r$pkgrel ocaml-runtime"
makedepends="dune ocaml ocaml-compiler-libs ocaml-cppo ocaml-findlib opam"
subpackages="$pkgname-dev $pkgname-data::noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/yoriyuki/$_pkgname/archive/$pkgver.tar.gz"
builddir="$srcdir/Camomile-$pkgver"

build() {
	cd "$builddir"

	# Workaround for https://github.com/yoriyuki/Camomile/issues/39.
	if [ "$CARCH" = ppc64le ]; then
		ulimit -Hs unlimited
		ulimit -Ss 65536
	fi

	jbuilder build @install
}

check() {
	cd "$builddir"
	jbuilder runtest
}

package() {
	cd "$builddir"

	mkdir -p "$pkgdir"/usr/lib/ocaml
	jbuilder install \
		--destdir="$pkgdir/usr" \
		--libdir="$pkgdir/usr/lib/ocaml"

	# There's just a readme and changelog.
	rm -Rf "$pkgdir"/usr/doc

	# Remove annotation files and sources.
	find "$pkgdir"/usr/lib/ocaml/$_pkgname \( \
		-name '*.cmt' -o \
		-name '*.cmti' -o \
		-name '*.ml' -o \
		-name '*.ml-gen' \) -delete
}

dev() {
	default_dev
	depends="$pkgname=$pkgver-r$pkgrel"

	cd "$pkgdir"

	local path; for path in $(find usr/lib/ocaml/$_pkgname \
		-name '*.cmx' -o \
		-name '*.cmxa' -o \
		-name '*.mli')
	do
		mkdir -p "${path%/*}"
		mv "$path" "$subpkgdir"/${path%/*}/
	done
}

data() {
	pkgdesc="$pkgdesc (data files)"
	depends=""

	mkdir -p "$subpkgdir"/usr/share
	mv "$pkgdir"/usr/share/$_pkgname "$subpkgdir"/usr/share/
}

sha512sums="41c453a55d284f879e390ef341482ad5c3dccb1cfd3720fd8513555276dde2397b657c632aa9b02f12f7990adb57bd7c3add637e30606c8f9ab5d28454eddfef  ocaml-camomile-1.0.1.tar.gz"
